/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import abstractmodel.InfoValue;
import java.text.DateFormat;

/**
 *
 * @author fightfxj
 */
public class BankAccountInfo implements abstractmodel.IInfo {
    
    private String accountName;           //帐户名称 长度不超过20 的字符串
    private String bankName;               // 归属银行 长度不超过20 的字符串
    private String accountNumber;        //卡号 长度不超过40 的字符串
    private String userName;                //开户名 长度不超过20 的字符串
    private String startUserTimeString;  //String类型的使用时间
    private DateFormat startUserTime;   //开户日期 yyyy-mm-dd 格式，长度为10的字符串
    private String accountType;            //类型 “活期”或者“定期”
    public static String[] titles = new String[]{"帐户名称", "归属银行", "卡号", "开户名", "开户日期", "类型"};
    private int id;

    public BankAccountInfo() {
        accountName = new String("银行账户名称");
        bankName = new String("归属银行");
        accountNumber = new String("000000");
        userName = new String("用户名");
        startUserTimeString = new String();
        startUserTime = DateFormat.getDateTimeInstance();
        accountType = BankAccountType.ACCOUNT_CURRENT_TYPE;     //默认为活期存款，BankAccountType存储“活期”或者“定期”的字符串常量        
    }
    
    public String getAccountName() {
        return accountName;
    }

    public String getAccountNunber() {
        return accountNumber;
    }

    public String getAccountType() {
        return accountType;
    }

    public String getBankName() {
        return bankName;
    }

    public String getStartUserTimeString() {
        return startUserTimeString;
    }
    
    public DateFormat getStartUserTime() {
        return startUserTime;
    }

    public String getUserName() {
        return userName;
    }
    
    @Override
    public String[] getTitles() {
        return BankAccountInfo.titles;
    }

    @Override
    public InfoValue getValue(String title) {
        InfoValue iv = new InfoValue();
        if (title.equals("帐户名称")) {
            iv.setObj(this.accountName);
            iv.setType(String.class);
        }
        else if (title.equals("归属银行")) {
            iv.setObj(this.bankName);
            iv.setType(String.class);
        }   
        else if (title.equals("卡号")) {
            iv.setObj(this.accountNumber);
            iv.setType(String.class);
        }   
        else if (title.equals("开户名")) {
            iv.setObj(this.userName);
            iv.setType(String.class);
        }   
        else if (title.equals("开户日期")) {
            iv.setObj(this.startUserTimeString);
            iv.setType(String.class);
        }   
        else if (title.equals("类型")) {
            iv.setObj(this.accountType);
            iv.setType(String.class);
        } 
        else if (title.equalsIgnoreCase("id")) {
            iv.setObj(new Integer(this.id).toString());
            iv.setType(String.class);
        }
  
        return iv;
        
    }

    @Override
    public boolean setValue(String title, Object value) {
        if (title.equals("帐户名称")) {
            this.accountName = value.toString();
        }
        else if (title.equals("归属银行")) {
            this.bankName = value.toString();
        }   
        else if (title.equals("卡号")) {
            this.accountNumber = value.toString();
        }   
        else if (title.equals("开户名")) {
            this.userName  = value.toString();
        }   
        else if (title.equals("开户日期")) {
            try {
                this.startUserTime = DateFormat.getDateInstance();
                this.startUserTime.getCalendar().setTime(configure.Global.sdf.parse(value.toString()));
                this.startUserTimeString = value.toString();
            } catch (Exception e) {
                System.out.println("Exception in set time of BankAccountInfo");
            }
        }   
        else if (title.equals("类型")) {
            this.accountType = value.toString();
        }   
        ModelFactory.data.saveUser(ModelFactory.ur);
        return true;
    }

    @Override
    public int getid() {
        return this.id;
    }

    @Override
    public void setId(int id) {
        this.id = id;
    }

    @Override
    public int getType() {
        return configure.Global.BANK_ACCOUNT_INFO_TYPE;
    }

}
